﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">教师信息</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <span class="k-textbox k-space-right">
                <input type="text" id="txtKey" />
                <a href="javascript:FilterTeacher()" class="k-icon k-i-search">&nbsp;</a>
            </span>
            <button class="k-button" onclick="CreateNewTeacher()"><span class="k-icon k-i-plus"></span><span>添加新教师</span></button>
        </div>
        <div id="grid_teacher" style="text-align: center"></div>
    </div>
</div>

<script class="init">
    LocatedMenu("学校管理", "体育教师");
</script>

<script class="grid_teacher_columns">
    var teacherFields = [{
        title: "教师姓名",
        field: "RealName",
        width: 200
    }, {
        title: "联系手机",
        field: "Mobile",
        width: 200
    }, {
        title: "添加时间",
        template: "#=kendo.toString(kendo.parseDate(CreatedOn),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "操作",
        template: "#=GetOperations(Guid)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(guid) {
        var html = "<button class='k-button' onclick=\"EditTeacher('" + guid + "')\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"DeleteTeacher('" + guid + "')\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        return html;
    }

    function EditTeacher(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改学生信息" });
            wndGeneralEdit.refresh({ url: "/School/Teacher/Edit/@ViewBag.SchoolGuid/" + guid });
            wndGeneralEdit.open();
        }
    }

    function DeleteTeacher(guid) {
        if (confirm("真的要删除这个教师吗？")) {
            Whale.Remote.Operation({
                url: "/School/Teacher/DeleteTeacher",
                parameters: { guid: guid },
                success: function (result) {
                    FilterTeacher();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_teacher").kendoGrid({
            columns: teacherFields,
            dataSource: Whale.dataSource({
                url: "/School/Teacher/GetTeachers",
                getParameters: function () {
                    return {
                        schoolGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid",
                        key: $.trim($("#txtKey").val())
                    };
                },
                pageSize: 20

            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });
</script>

<script class="fn">
    function CreateNewTeacher() {
        wndGeneralEdit.setOptions({ title: "添加新的教师" });
        wndGeneralEdit.refresh({ url: "/School/Teacher/Edit/@ViewBag.SchoolGuid" });
        wndGeneralEdit.open();
    }

    function FilterTeacher() {
        $("#grid_teacher").data("kendoGrid").dataSource.page(0);
    }

</script>
